{# Form macros. Native inputs with ``name`` attributes, so every form posts or re-queries through htmx without client-side state. {% from "components/macros/form.html" import field, text_input, select, date_input, primary_button %} #} {% from "components/macros/icons.html" import icon %} {# Shared control styling: DaisyUI's control of ``kind`` (input, select, textarea, checkbox, radio) in its small form; the text controls sit bordered on the page surface so a bar of them reads as one. DaisyUI owns focus, disabled and placeholder states; the theme owns radius and color. Templates never spell a DaisyUI control class themselves. #} {# DaisyUI draws its own 2px outline on focus; the teal border is the focus cue here, so the outline goes. #} {% set _surface = "bg-aegis-bg text-aegis-text focus:border-aegis-teal focus:outline-none focus-within:outline-none [&:user-invalid]:border-error" %} {# Class names are spelled in full: Tailwind emits only what it can read from the source, so a name built from parts would never compile. #} {% macro control(kind) -%} {{ { "input": "input input-bordered input-sm " ~ _surface, "select": "select select-bordered select-sm " ~ _surface, "textarea": "textarea textarea-bordered textarea-sm " ~ _surface, "checkbox": "checkbox checkbox-primary checkbox-xs", "radio": "radio radio-primary radio-xs", }[kind] }} {%- endmacro %} {# Buttons are DaisyUI's: outline so the data stays louder than the controls; ``tone`` is default (quiet: muted text and border, which DaisyUI has no outline variant for), primary (teal), danger or warn; ``size`` sm for a form's verbs, xs for a row's. Hover, focus, disabled and the press scale come with it; the theme owns radius and color. #} {% macro button_classes(tone="primary", size="sm") -%} {% set tones = {"default": "border-aegis-border text-aegis-muted hover:border-aegis-muted hover:text-aegis-text hover:bg-aegis-border/20", "primary": "btn-primary", "danger": "btn-error", "warn": "btn-warning"} %} btn btn-outline {{ {"sm": "btn-sm", "xs": "btn-xs"}[size] }} {{ tones.get(tone, tones["default"]) }} {%- endmacro %} {# Inline primary button (no loading spinner). Defaults to ``type="button"`` so it doesn't accidentally submit a form it's nested inside — pass ``type="submit"`` explicitly when you want submit semantics. ``attrs`` lets the caller pass other attributes (Alpine ``@click``, ``:disabled``, ``aria-*``), never a ``type=`` (refused). ``filled`` is the page's one action. #} {% macro primary_button(label, type="button", attrs="", filled=False) %} {% endmacro %} {# Primary submit button with an inline loading spinner. Parent scope must expose ``loading`` (bool) — typically flipped by ``@submit="loading = true"`` on the form. The button disables itself while loading so a double-click can't double-submit. #} {% macro submit_button(idle_label, loading_label) %} {% endmacro %} {# A native select. ``options`` are objects or dicts with ``id`` and ``name``, or, ``grouped``, ``{"label", "options"}`` groups of them (an optgroup each); ``blank`` is the "no filter" label (``None`` for no blank choice), chosen while nothing is; ``selected`` the current id. ``label`` wraps it inline for a filter bar; ``block`` lays it out full-width inside a ``field()``; ``attrs`` rides on the select. #} {% macro select(name, options, selected=None, blank="All", label=None, block=False, grouped=False, attrs="") %} {% if label %}{% endif %} {% endmacro %} {% macro date_input(name, value=None, label=None, block=False) %} {% if label %}{% endif %} {% endmacro %} {# Every file picker: the native input hidden behind a button-styled label, so it looks like every other button. Picking submits its form (an upload button); with ``submit=False`` it keeps what was picked (a second pick adds to the first, where ``multiple``), says how many and how big, and lists each, removable (the ``filePicker`` component in app.js), for a form with its own submit. #} {% macro file_button(id, label, accept=None, name="file", submit=True, required=True, multiple=False) %} {%- set button = button_classes("primary", "xs") -%} {%- set input -%}{%- endset -%} {%- set picker -%}{{ input }}{%- endset -%} {% if submit %} {{ picker }} {% else %}
{{ error }}
{% endif %} {% if hint %}{{ hint }}
{% endif %}